using Pegasus.Diagnostics;
using Pegasus.Windows.Forms;
using System;

namespace Pegasus
{
	/// <summary>
	/// Summary description for ExceptionManager.
	/// </summary>
	public class ExceptionManager
	{
		// Local Instance Values
		private AppDomain m_appDomain;

		/// <summary>
		/// 
		/// </summary>
		/// <param name="domain"></param>
		public ExceptionManager( AppDomain domain )
		{
			// Check params
			ParamCode.AssertNotNull( domain, "domain" );

			m_appDomain = domain;
			m_appDomain.UnhandledException += new UnhandledExceptionEventHandler( AppDomain_UnhandledException );
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="args"></param>
		private void AppDomain_UnhandledException( object sender, UnhandledExceptionEventArgs args )
		{
			// Check params
			ParamCode.AssertNotNull( sender, "sender" );
			ParamCode.AssertNotNull( args, "args" );
			ParamCode.AssertNotNull( args.ExceptionObject, "args.ExceptionObject" );

			MsgBox.ErrorBox( "[Unhandled Exception]", (Exception) args.ExceptionObject );
		}
	}
}
